package com.zenika.amqp;

import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class AMQPSender {

	private static Logger logger = Logger.getLogger(AMQPSender.class);

	private AmqpTemplate template;

	@Before
	public void before() {
		ApplicationContext context = new GenericXmlApplicationContext("classpath:/spring-context-sender.xml");
		template = context.getBean(AmqpTemplate.class);
	}

	@Test
	public void sendMessages() throws Exception {

		while (true) {

			Cotation cotation = CotationBuilder.buildCotation();
			template.convertAndSend("zenika.cotation", cotation.getMarche(), cotation);

			logger.info(">>> SENDING ==> " + cotation);
			//Thread.sleep(1000);
		}
	}

}
